#include <cstring>
#include "strtrim.h"

/*去除字符串中所有空格*/
int StrTrim(const char*src,int len,char* dest){
    strcpy(dest,src);
    int i = 1;
    int j = 0;
    while (i <= len)
    {
        if (*src != ' ')
        {
            *dest++ = *src;
            ++j;
        }
        ++src;
        ++i;
    }
    return j;
}

/*去除字符串中所有空格*/
void StrTrim(char*pStr)
{
    char *pTmp = pStr;
    while (*pStr != '/0')
    {
        if (*pStr != ' ')
        {
            *pTmp++ = *pStr;
        }
        ++pStr;
    }
    *pTmp = '/0';
}
/*去除字符串右边空格*/
void StrRTrim(char *pStr)
{
    char *pTmp = pStr+strlen(pStr)-1;
    while (*pTmp == ' ')
    {
        *pTmp = '/0';
        pTmp--;
    }
}
/*去除字符串左边空格*/
void StrLTrim(char *pStr)
{
    char *pTmp = pStr;
    while (*pTmp == ' ')
    {
        pTmp++;
    }
    while(*pTmp != '/0')
    {
        *pStr = *pTmp;
        pStr++;
        pTmp++;
    }
    *pStr = '/0';
}